Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onDelay hook #47

Merged
merged 19 commits into from
Dec 7, 2023
Merged

onDelay hook #47

merged 19 commits into from
Dec 7, 2023

Conversation

dormeiri
Copy link
Contributor

@dormeiri dormeiri commented Dec 5, 2023

  • A callback that would be called when a call is delayed due to exceeding the interval limit.

Fixes #44

test.js Outdated
t.is(delayedCounter, delayedExecutions);

await Promise.all(promises);
t.pass();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t.pass();

This is moot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

index.d.ts Show resolved Hide resolved
index.d.ts Outdated
Comment on lines 45 to 46
/**
A callback for when a call gets delayed due to the number of calls in the `interval` exceeded the `limit`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
A callback for when a call gets delayed due to the number of calls in the `interval` exceeded the `limit`.
/**
Get notified when function calls are delayed due to exceeding the `limit` of allowed calls within a the given `interval`.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

index.d.ts Outdated
await throttled(); //=> Reached the interval limit, the call is delayed
```
*/
readonly onDelay?: () => void | Promise<void>;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
readonly onDelay?: () => void | Promise<void>;
readonly onDelay?: () => void;

It should not have Promise here when it does not actually await the returned promise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, removed

@sindresorhus
Copy link
Owner

Should be documented in the readme too.

@dormeiri
Copy link
Contributor Author

dormeiri commented Dec 5, 2023

Should be documented in the readme too.

Added to the readme

readme.md Outdated
const throttle = pThrottle({
limit: 2,
interval: 1000,
onDelay: () => console.log('Reached the interval limit, the call is delayed'),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the same as the one in index.d.ts (missing braces). Make sure they are both in sync.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Synced

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You synced it the wrong way.

The changes in ba5ef67 should be preserved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, fixed

@sindresorhus sindresorhus merged commit 362f1e1 into sindresorhus:main Dec 7, 2023
@benjamindell
Copy link

Is it possible to get details of the request being made when the onDelay callback is triggered?

@dormeiri
Copy link
Contributor Author

dormeiri commented Aug 6, 2024

We can add the arguments of the delayed call. Would that help?
@benjamindell

@benjamindell
Copy link

We can add the arguments of the delayed call. Would that help? @benjamindell

Hey @dormeiri - yes I think that should be good. Thanks

@dormeiri dormeiri deleted the onDelay_hook branch August 12, 2024 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a callback hook when throttled
3 participants